﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Sql;

public partial class Default2 : System.Web.UI.Page
{
    private string ay, yil;
    private DcSql conn;
    private string VT_Prim = "Prim";   

    protected void Page_Load(object sender, EventArgs e)
    {
        conn = new DcSql();
        string hataMesaji = conn.DBBaglan(VT_Prim);

        string selectSql = "select cari_per_kod,cari_per_adi from mikroDB.dbo.CARI_PERSONEL_TANIMLARI order by cari_per_adi ";

        SqlDataAdapter da = new SqlDataAdapter(selectSql,conn.GetConn());

        DataSet ds = new DataSet();
        da.Fill(ds,"Personel");

        cmbPersonel.DataSource = ds.Tables[0];
        cmbPersonel.TextField = "cari_per_adi";
        cmbPersonel.ValueField = "cari_per_kod";
        cmbPersonel.DataBind();

    }

    
    
    protected void btnHesapla_Click(object sender, EventArgs e)
    {
        
        string personelSql="";
        yil = ASPxSpinEdit1.Value.ToString();
        ay = (cmbAy.SelectedIndex + 1).ToString();

        if (cmbPersonel.Value.ToString().Length>0) 
            personelSql =  " and sPersonelKodu ='"+cmbPersonel.Value.ToString()+"'";

        string selectsql = " select PrimBonusID,sPersonelKodu, " +

                            "  dtTahsilatTarihi,nTahsilatBelgeTutari,tahsilat.cha_kod, " +

                            " (select cari_unvan1 from mikrodb.dbo.CARI_HESAPLAR h where h.cari_kod=tahsilat.cha_kod ) as cari_adi, " +

                            " tahsilat.cha_evrakno_seri+' '+Convert(varchar(10),tahsilat.cha_evrakno_sira) as tahsilat_evrak_seri_no, " +

                            " tahsilat.cha_vade, " +

                            " case  tahsilat.cha_evrak_tip when 1 then 'Nakit Tahsilat' else 'Havale' end cha_evrak_tip , " +

                            " nEslemeTutari,a.nPrimBonusTutari, " +

                            " fatura.cha_evrakno_seri+'-'+Convert(varchar(10),fatura.cha_evrakno_sira) as fatura_evrak_seri_no, " +

                            " fatura.cha_tarihi as fatura_tarihi, " +

                            " fatura.cha_meblag as fatura_tutari " +

                            " from PrimBonus a , FaturaEsleme b , mikrodb.dbo.CARI_HESAP_HAREKETLERI tahsilat ,mikrodb.dbo.CARI_HESAP_HAREKETLERI fatura " +
                            " where a.PrimBonusID = b.pPrimBonusID " +
                            "  and b.pTahsilatHareketID = tahsilat.cha_RECid_RECno " +
                            "  and b.pFaturaHareketID = fatura.cha_RECid_RECno " +
                            "  and a.nPrimBonusYil=" + yil + " and a.nPrimBonusAy=" + ay
                            + personelSql;
                           


        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(selectsql, conn.GetConn());

        da.Fill(ds, "Hakedis");

        gridListe.Visible = true;
        gridListe.DataSource = ds.Tables[0];
        gridListe.DataBind();

        if (!IsPostBack && !IsCallback)
            gridListe.DataBind();
    }
   
}